﻿using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;

namespace WpfTD
{
     public class PrintTdtj
    {
         public void printTdtj(List<VKPOS> objList)
         {

             //定义一个工作簿
             Microsoft.Office.Interop.Excel.Application excelApp = new Application();
             //路径
             string excelBookPath ="D:\\JLTProd\\Exe\\Report\\JLT\\JLTTDVKWB.xls";
             //现有的工作簿加到工作簿集合里面
             excelApp.Workbooks.Add(excelBookPath);
             //获取第一个工作簿
             Worksheet sheet1 = (Worksheet)excelApp.Worksheets[1];
             //Image objImage = (Image)new Common.SerializeObjectToString().DeserializeObject(objStudent.Image);
             //图片查询复制到文件夹
             //if (objStudent.Image.Length!=0)
             //{
             //    Image objImage = (Image)new Common.SerializeObjectToString().DeserializeObject(objStudent.Image);
             //    if (File.Exists(Environment.CurrentDirectory + "\\Student.jpg"))
             //    {
             //        File.Delete(Environment.CurrentDirectory + "\\Student.jpg");
             //    }
             //    else
             //    {
             //        objImage.Save(Environment.CurrentDirectory + "\\Student.jpg");
             //        sheet1.Shapes.AddPicture(Environment.CurrentDirectory + "\\Student.jpg",MsoTriState.msoFalse,MsoTriState.msoTrue,10,50,100,150);
             //        File.Delete(Environment.CurrentDirectory + "\\Student.jpg");
             //    }
             //}

             for (int i = 0; i < objList.Count; i++)
             {
                 sheet1.Cells[i + 3, 2] = objList[i].VKPART;
                 sheet1.Cells[i + 3, 3] = objList[i].VKPFARBE;
                 sheet1.Cells[i + 3, 4] = objList[i].VKPKKOLL;
                 sheet1.Cells[i + 3, 5] = objList[i].VKPMENGE1T2;
                 sheet1.Cells[i + 3, 6] = objList[i].WBBLENGTHCP;
                 sheet1.Cells[i + 3, 7] = objList[i].WBBLENGTHCW;
                 sheet1.Cells[i + 3, 8] = objList[i].WBBLENGTHKO;
                 sheet1.Cells[i + 3, 9] = objList[i].WBBLENGTHLB;
                 sheet1.Cells[i + 3, 10] = objList[i].WBBLENGTHDC;
             }
             //sheet1.Cells[4, 4] = 
             //sheet1.Cells[4, 6] = objStudent.StudentName;
             //sheet1.Cells[4, 8] = objStudent.Gender;
             //sheet1.Cells[6,4] = objStudent.ClassName;
             //sheet1.Cells[6, 6] = objStudent.PhoneNumber;
             //sheet1.Cells[8, 4] = objStudent.StudentAddress;
             //打印预览
             excelApp.Visible = true;
             //excelApp.Sheets.PrintPreview(true);
             //excelApp.Quit();
             System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
             excelApp = null;

         }

    }
}
